package person.wend.springbootlearnexample2.health;

import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class CustomStatusHttpMapper implements HttpCodeStatusMapper {

    private final Map<String, Integer> statusMapping;

    public CustomStatusHttpMapper() {
        this.statusMapping = new HashMap<>();
        statusMapping.put("running", 200);
        statusMapping.put("error", 503);
        statusMapping.put("outOfService", 503);
        statusMapping.put("unknow", 200);
    }

    @Override
    public int getStatusCode(Status status) {
        System.out.println("status.getCode() = " + status.getCode());
        return statusMapping.getOrDefault(status.getCode(), 500);
    }
}